{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "0baac6c4-0b87-4bef-b83a-d7cbd00bff63",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import openpyxl\n",
    "import datetime\n",
    "from colorsys import rgb_to_hls, hls_to_rgb\n",
    "from openpyxl.styles.colors import COLOR_INDEX\n",
    "import warnings\n",
    "warnings.filterwarnings('ignore')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "bee876ce-eee4-4f03-8453-b82a81c3d05a",
   "metadata": {},
   "outputs": [],
   "source": [
    "resource = pd.read_excel('L3.xlsx', sheet_name='resource')\n",
    "wb = openpyxl.load_workbook('L3.xlsx')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "c1a412a1-fe19-4016-ba48-0a90a3c02d7f",
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_cell_color(cell):\n",
    "    theme_color = ThemeColorConverter(wb) # 获取基础色调\n",
    "    color = cell.fill.start_color\n",
    "    if color.type == \"rgb\":\n",
    "        return color.rgb\n",
    "    elif color.type == \"indexed\":\n",
    "        color_index = color.indexed\n",
    "        if color_index is None or color_index < len(COLOR_INDEX):\n",
    "            raise Exception(\"Invalid indexed color\")\n",
    "        return COLOR_INDEX[color_index]\n",
    "    elif color.type == \"theme\":\n",
    "        return \"FF\" + theme_color.theme_and_tint_to_rgb(color.theme, color.tint)\n",
    "    else:\n",
    "        raise Exception(f\"Other type: {color.type}\")\n",
    "        \n",
    "copper_color = get_cell_color(wb['resource']['B1'])\n",
    "tin_color = get_cell_color(wb['resource']['C1'])\n",
    "icon_color = get_cell_color(wb['resource']['D1'])\n",
    "mithril_color = get_cell_color(wb['resource']['E1'])\n",
    "thorium_color = get_cell_color(wb['resource']['F1'])\n",
    "\n",
    "schedule = wb['mining schedule']\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d4fe323a-1dda-41e9-928a-89f463524211",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e8d7f6ae-2350-4c76-ae74-d59277a598fa",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "9c6c5a4e-79d4-447a-874b-f4ba79a91b81",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1684.0000000000005\n"
     ]
    }
   ],
   "source": [
    "def check_resource(color):\n",
    "    if color == copper_color:\n",
    "        return 'Copper'\n",
    "    elif color == tin_color:\n",
    "        return 'Tin'\n",
    "    elif color == icon_color:\n",
    "        return 'Iron'\n",
    "    elif color == mithril_color:\n",
    "        return 'Mithril'\n",
    "    elif color == thorium_color:\n",
    "        return 'Thorium'\n",
    "\n",
    "player_id = 20\n",
    "gold_collected = 56.88\n",
    "resource_remain = {\n",
    "    'Copper': 0, \n",
    "    'Tin': 0, \n",
    "    'Iron': 0, \n",
    "    'Mithril': 0, \n",
    "    'Thorium': 0, \n",
    "    'gold_collected': gold_collected,\n",
    "    'week': '1'\n",
    "}\n",
    "\n",
    "\n",
    "while True:\n",
    "    # week 1\n",
    "    resource_type = check_resource(get_cell_color(schedule.cell(player_id+1, 2)))\n",
    "    start_date = schedule.cell(player_id+1, 1).value\n",
    "    sell_date = start_date + datetime.timedelta(days=6)\n",
    "    resource_remain['week'] = '1'\n",
    "    \n",
    "    stack = schedule.cell(player_id+1, 2).value // 20\n",
    "    resource_remain[resource_type] = schedule.cell(player_id+1, 2).value % 20 + resource_remain[resource_type]\n",
    "\n",
    "    resource_remain['gold_collected'] = (resource[resource['date'] == sell_date][resource_type] * stack).values[0] + resource_remain['gold_collected']\n",
    "    for i in ['Copper', 'Tin', 'Iron', 'Mithril', 'Thorium']:\n",
    "        if resource_remain[i] >= 20:\n",
    "            stack = resource_remain[i] // 20\n",
    "            resource_remain[i] = resource_remain[i] % 20\n",
    "            resource_remain['gold_collected'] = (resource[resource['date'] == sell_date][i]*stack).values[0] + resource_remain['gold_collected']\n",
    "    if resource_remain['gold_collected'] >= 90:\n",
    "        break\n",
    "    \n",
    "    # week 2\n",
    "    resource_type = check_resource(get_cell_color(schedule.cell(player_id+1, 3)))\n",
    "    start_date = start_date + datetime.timedelta(days=7)\n",
    "    sell_date = start_date + datetime.timedelta(days=6)\n",
    "    resource_remain['week'] = '2'\n",
    "    stack = schedule.cell(player_id+1, 3).value // 20\n",
    "    resource_remain[resource_type] = schedule.cell(player_id+1, 3).value % 20 + resource_remain[resource_type]\n",
    "    resource_remain['gold_collected'] = (resource[resource['date'] == sell_date][resource_type] * stack).values[0] + resource_remain['gold_collected']\n",
    "\n",
    "    for i in ['Copper', 'Tin', 'Iron', 'Mithril', 'Thorium']:\n",
    "        if resource_remain[i] >= 20:\n",
    "            stack = resource_remain[i] // 20\n",
    "            resource_remain[i] = resource_remain[i] % 20\n",
    "            resource_remain['gold_collected'] = (resource[resource['date'] == sell_date][i]*stack).values[0] + resource_remain['gold_collected']\n",
    "    if resource_remain['gold_collected'] >= 90:\n",
    "        break\n",
    "\n",
    "    \n",
    "    # week 3\n",
    "    resource_type = check_resource(get_cell_color(schedule.cell(player_id+1, 4)))\n",
    "    start_date = start_date + datetime.timedelta(days=7)\n",
    "    sell_date = start_date + datetime.timedelta(days=6)\n",
    "    resource_remain['week'] = '3'\n",
    "    stack = schedule.cell(player_id+1, 4).value // 20\n",
    "    resource_remain[resource_type] = schedule.cell(player_id+1, 4).value % 20 + resource_remain[resource_type]\n",
    "    resource_remain['gold_collected'] = (resource[resource['date'] == sell_date][resource_type] * stack).values[0] + resource_remain['gold_collected']\n",
    "\n",
    "    for i in ['Copper', 'Tin', 'Iron', 'Mithril', 'Thorium']:\n",
    "        if resource_remain[i] >= 20:\n",
    "            stack = resource_remain[i] // 20\n",
    "            resource_remain[i] = resource_remain[i] % 20\n",
    "            resource_remain['gold_collected'] = (resource[resource['date'] == sell_date][i]*stack).values[0] + resource_remain['gold_collected']\n",
    "    if resource_remain['gold_collected'] >= 90:\n",
    "        break\n",
    "\n",
    "    \n",
    "    # week 4\n",
    "    resource_type = check_resource(get_cell_color(schedule.cell(player_id+1, 5)))\n",
    "    start_date = start_date + datetime.timedelta(days=7)\n",
    "    sell_date = start_date + datetime.timedelta(days=6)\n",
    "    resource_remain['week'] = '4'\n",
    "    stack = schedule.cell(player_id+1, 5).value // 20\n",
    "    resource_remain[resource_type] = schedule.cell(player_id+1, 5).value % 20 + resource_remain[resource_type]\n",
    "    resource_remain['gold_collected'] = (resource[resource['date'] == sell_date][resource_type] * stack).values[0] + resource_remain['gold_collected']\n",
    "    for i in ['Copper', 'Tin', 'Iron', 'Mithril', 'Thorium']:\n",
    "        if resource_remain[i] >= 20:\n",
    "            stack = resource_remain[i] // 20\n",
    "            resource_remain[i] = resource_remain[i] % 20\n",
    "            resource_remain['gold_collected'] = (resource[resource['date'] == sell_date][i]*stack).values[0] + resource_remain['gold_collected']\n",
    "    if resource_remain['gold_collected'] >= 90:\n",
    "        break\n",
    "    \n",
    "    # week 5\n",
    "    resource_type = check_resource(get_cell_color(schedule.cell(player_id+1, 6)))\n",
    "    start_date = start_date + datetime.timedelta(days=7)\n",
    "    sell_date = start_date + datetime.timedelta(days=6)\n",
    "    resource_remain['week'] = '5'\n",
    "    stack = schedule.cell(player_id+1, 6).value // 20\n",
    "    resource_remain[resource_type] = schedule.cell(player_id+1, 6).value % 20 + resource_remain[resource_type]\n",
    "    resource_remain['gold_collected'] = (resource[resource['date'] == sell_date][resource_type] * stack).values[0] + resource_remain['gold_collected']\n",
    "    for i in ['Copper', 'Tin', 'Iron', 'Mithril', 'Thorium']:\n",
    "        if resource_remain[i] >= 20:\n",
    "            stack = resource_remain[i] // 20\n",
    "            resource_remain[i] = resource_remain[i] % 20\n",
    "            resource_remain['gold_collected'] = (resource[resource['date'] == sell_date][i]*stack).values[0] + resource_remain['gold_collected']\n",
    "    if resource_remain['gold_collected'] >= 90:\n",
    "        break\n",
    "    \n",
    "\n",
    "print((resource_remain['gold_collected'] - 90) * 100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "3370f921-70af-4623-a09b-e3f2e33e27b5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_items([('copper_stack', 22), ('gold_collect', 22.85)])"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "resource_remain = {\n",
    "    'copper_stack': 22, \n",
    "    'tin_stack': 0, \n",
    "    'icon_stack': 0, \n",
    "    'mithril_stack': 0, \n",
    "    'thorium_stack': 0, \n",
    "    'gold_collect': 22.85\n",
    "}\n",
    "# dict(filter(lambda x: x[1] > 20, resource_remain.items()))\n",
    "{key: value for key, value in resource_remain.items() if value >= 20}.items()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4c1f060e-1bfa-4885-9ee3-0e7ddaa9707d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "8a9c9c2c-77b7-4cf3-ada5-05ba2cfe355b",
   "metadata": {},
   "outputs": [],
   "source": [
    "# L1\n",
    "import pandas as pd\n",
    "\n",
    "upgrade_xp = [400]  # 升级所需经验\n",
    "total_xp = [0]  # 累积经验\n",
    "for i in range(1, 100):\n",
    "    total_xp.append(total_xp[i-1] + upgrade_xp[i-1])\n",
    "    upgrade_xp.append(upgrade_xp[i-1]*1.125)\n",
    "\n",
    "# 为了直观看到他们的关系，写进一个表格内\n",
    "degree = pd.DataFrame({'degree': range(1, 101), 'total_xp': total_xp, 'upgrade_xp': upgrade_xp})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7f025eaf-d6d9-4914-96be-52cdb21c2f07",
   "metadata": {},
   "outputs": [],
   "source": [
    "# L2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "7be0bdee-15f7-4465-8dea-69094b593d03",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(315908, 5725.0)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "location = pd.read_excel('L2.xlsx', sheet_name='location')   # 加载种族位置顺序表\n",
    "site = pd.read_excel('L2.xlsx', sheet_name='site')   # 任务顺序表\n",
    "\n",
    "\n",
    "def get_money(race, xp, gold_collected, current_location):\n",
    "    '''\n",
    "    :param race: 种族\n",
    "    :param xp: 初始xp\n",
    "    :param gold_collected: 已获得的金币\n",
    "    :param current_location: 当前位置\n",
    "    :return: 达到40级后的银币数量\n",
    "    '''\n",
    "    degree_xp = degree[degree['degree'] == 40]['total_xp'].values[0]  # 达到40级的累积经验\n",
    "    race_location_sort = location[race] # 根据种族查找位置顺序\n",
    "    quest_location = list(race_location_sort).index(current_location)\n",
    "    df = site[site['Location'].isin(race_location_sort[quest_location:])]\n",
    "    df['Location'] = pd.Categorical(df['Location'], categories=race_location_sort)\n",
    "    df = df.sort_values(['Location', 'Quest ID'])\n",
    "    df['gold_collected_cumsum'] = df['Gold Granted'].cumsum()\n",
    "    df['xp_cumsum'] = df['XP Granted'].cumsum()\n",
    "    total_xp = df[df['xp_cumsum'] > (degree_xp - xp)]['xp_cumsum'].min()  # 达到40级时获得的xp\n",
    "    gold_granted = df[df['xp_cumsum'] > (degree_xp - xp)]['gold_collected_cumsum'].min()  # 达到40级时获得的金币\n",
    "    total_xp += xp\n",
    "    sliver_collected = (gold_collected + gold_granted) * 100\n",
    "    return total_xp, sliver_collected\n",
    "\n",
    "get_money('Orc', 908, 28.78, 'Durotar')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "507f85d4-6d1d-41d7-a6a8-7c8eabe6c187",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "58946bd3-8782-44ae-80ad-d58e2c9aead0",
   "metadata": {},
   "outputs": [],
   "source": [
    "class ThemeColorConverter:\n",
    "    RGBMAX = 0xff\n",
    "    HLSMAX = 240\n",
    "\n",
    "    def __init__(self, wb):\n",
    "        self.colors = self.get_theme_colors(wb)\n",
    "\n",
    "    @staticmethod\n",
    "    def tint_luminance(tint, lum):\n",
    "        if tint < 0:\n",
    "            return int(round(lum * (1.0 + tint)))\n",
    "        return int(round((ThemeColorConverter.HLSMAX - lum) * tint)) + lum\n",
    "\n",
    "    @staticmethod\n",
    "    def ms_hls_to_rgb(hue, lightness=None, saturation=None):\n",
    "        if lightness is None:\n",
    "            hue, lightness, saturation = hue\n",
    "        hlsmax = ThemeColorConverter.HLSMAX\n",
    "        return hls_to_rgb(hue / hlsmax, lightness / hlsmax, saturation / hlsmax)\n",
    "\n",
    "    @staticmethod\n",
    "    def rgb_to_hex(red, green=None, blue=None):\n",
    "        if green is None:\n",
    "            red, green, blue = red\n",
    "        return '{:02X}{:02X}{:02X}'.format(\n",
    "            int(red * ThemeColorConverter.RGBMAX),\n",
    "            int(green * ThemeColorConverter.RGBMAX),\n",
    "            int(blue * ThemeColorConverter.RGBMAX)\n",
    "        )\n",
    "\n",
    "    @staticmethod\n",
    "    def rgb_to_ms_hls(red, green=None, blue=None):\n",
    "        if green is None:\n",
    "            if isinstance(red, str):\n",
    "                if len(red) > 6:\n",
    "                    red = red[-6:]  # Ignore preceding '#' and alpha values\n",
    "                rgbmax = ThemeColorConverter.RGBMAX\n",
    "                blue = int(red[4:], 16) / rgbmax\n",
    "                green = int(red[2:4], 16) / rgbmax\n",
    "                red = int(red[0:2], 16) / rgbmax\n",
    "            else:\n",
    "                red, green, blue = red\n",
    "        h, l, s = rgb_to_hls(red, green, blue)\n",
    "        hlsmax = ThemeColorConverter.HLSMAX\n",
    "        return (int(round(h * hlsmax)), int(round(l * hlsmax)),\n",
    "                int(round(s * hlsmax)))\n",
    "\n",
    "    @staticmethod\n",
    "    def get_theme_colors(wb):\n",
    "        from openpyxl.xml.functions import QName, fromstring\n",
    "        xlmns = 'http://schemas.openxmlformats.org/drawingml/2006/main'\n",
    "        root = fromstring(wb.loaded_theme)\n",
    "        themeEl = root.find(QName(xlmns, 'themeElements').text)\n",
    "        colorSchemes = themeEl.findall(QName(xlmns, 'clrScheme').text)\n",
    "        firstColorScheme = colorSchemes[0]\n",
    "        colors = []\n",
    "        for c in ['lt1', 'dk1', 'lt2', 'dk2', 'accent1', 'accent2', 'accent3', 'accent4', 'accent5', 'accent6']:\n",
    "            accent = firstColorScheme.find(QName(xlmns, c).text)\n",
    "            for i in list(accent):\n",
    "                if 'window' in i.attrib['val']:\n",
    "                    colors.append(i.attrib['lastClr'])\n",
    "                else:\n",
    "                    colors.append(i.attrib['val'])\n",
    "        return colors\n",
    "\n",
    "    def theme_and_tint_to_rgb(self, theme, tint):\n",
    "        rgb = self.colors[theme]\n",
    "        h, l, s = self.rgb_to_ms_hls(rgb)\n",
    "        return self.rgb_to_hex(self.ms_hls_to_rgb(h, self.tint_luminance(tint, l), s))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "ff9fd1a7-94e1-4892-9042-aa969daa218d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e6f3c49b-20c8-4239-82be-a891537807cf",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "913d1591-1fd8-44d9-8059-8407613d7e03",
   "metadata": {},
   "outputs": [],
   "source": [
    "# L4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "a2ccdd1b-3433-4e94-9bdb-90e85b9dcf6e",
   "metadata": {},
   "outputs": [],
   "source": [
    "quest_list = pd.read_excel('L4.xlsx', sheet_name='Quest List')\n",
    "quest_item = pd.read_excel('L4.xlsx', sheet_name='Quest Item')\n",
    "class_stat = pd.read_excel('L4.xlsx', sheet_name='Stat')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7a10280e-efb0-4275-9e8d-2ee84aeae3a1",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "cb66a9bf-eb8e-4075-9676-f5be710869be",
   "metadata": {},
   "outputs": [],
   "source": [
    "data = pd.merge(quest_list, quest_item, left_on='Item Granted', right_on='Item Name', how='left')\n",
    "player_class = 'Warlock'\n",
    "player_xp, sliver_granted = get_money('Orc', 908, 28.78, 'Durotar') # 由Level2计算的xp\n",
    "gold_granted = sliver_granted / 100\n",
    "target = class_stat[class_stat['Class'] == player_class]['Target'].values[0]\n",
    "\n",
    "if player_class in ['Warlock', 'Priest', 'Mage']:\n",
    "    player_class = 'Warlock, Priest, Mage'\n",
    "elif player_class in ['Druid', 'Rogue']:\n",
    "    player_class = 'Druid, Rogue'\n",
    "\n",
    "\n",
    "class_data = data[data['Available to Class'] == player_class]\n",
    "class_data.sort_values(by=['Amount of Stats', 'XP Granted'], ascending=False, inplace=True)\n",
    "\n",
    "class_data['total_stat'] = class_data['Amount of Stats'].cumsum()\n",
    "class_data['xp_granted'] = class_data['XP Granted'].cumsum()\n",
    "player_xp = class_data[class_data['total_stat'] >= target]['xp_granted'].values[0] + player_xp\n",
    "gold_granted = class_data[class_data['total_stat'] >= target]['Gold Granted'].values[0] + gold_granted\n",
    "stats_amount = class_data[class_data['total_stat'] >= target]['total_stat'].values[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9c6af359-a2ab-4a25-854d-778c3485cc58",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "308beced-9e5f-4db3-9e0c-e41025435333",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "081e058b-7d74-44a3-b861-cac8e80381cd",
   "metadata": {},
   "outputs": [],
   "source": [
    "# L5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "4e52c51b-a2fd-400e-ae3a-57ba5d0b5199",
   "metadata": {},
   "outputs": [],
   "source": [
    "dungeons = pd.read_excel('L5.xlsx')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "93dcfe1a-39a4-4c17-9d12-0a5b7d5e8ad4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "386368 41 61.1 85 0\n",
      "441368 42 66.0 85 0\n",
      "496368 43 69.37 85 0\n",
      "561368 44 72.62 85 0\n",
      "626368 45 75.38000000000001 85 0\n",
      "691368 46 79.15 85 0\n",
      "761368 47 82.80000000000001 188 103\n",
      "836368 48 89.15 188 103\n",
      "911368 49 93.76 188 103\n",
      "986368 49 99.46000000000001 188 103\n",
      "1061368 50 105.81 188 103\n",
      "1141368 50 112.06 188 103\n",
      "1221368 51 118.47 188 103\n",
      "1301368 52 122.85 188 103\n",
      "1391368 52 131.2 188 103\n",
      "1481368 53 136.35 188 103\n",
      "1571368 53 143.17 188 103\n",
      "1661368 54 151.51999999999998 188 103\n",
      "1761368 54 159.73999999999998 188 103\n",
      "1861368 55 167.55999999999997 188 103\n",
      "1961368 55 173.85999999999999 200 115\n",
      "2061368 55 182.07999999999998 200 115\n",
      "2161368 56 189.89999999999998 200 115\n",
      "2271368 56 196.89 200 115\n",
      "2381368 57 204.23 200 115\n",
      "2491368 57 210.91 200 115\n",
      "2601368 57 217.9 200 115\n",
      "2711368 58 225.24 200 115\n",
      "2826368 58 234.24 200 115\n",
      "2941368 58 243.21 200 115\n",
      "3056368 59 250.22 200 115\n",
      "3171368 59 259.22 200 115\n",
      "3286368 59 268.19000000000005 200 115\n",
      "3401368 60 275.20000000000005 200 115\n",
      "27520.000000000004\n"
     ]
    }
   ],
   "source": [
    "player_class = 'Warlock'\n",
    "player_degree = 40\n",
    "visit_on_degree = 1\n",
    "armor_stats = 0\n",
    "armor_price = 0\n",
    "armor = 'null'\n",
    "    \n",
    "\n",
    "if player_class == 'Mage':\n",
    "    player_class = 'Warlock, Mage'\n",
    "\n",
    "while True:\n",
    "    df = dungeons[dungeons['Min Level'] <= player_degree]\n",
    "    df.sort_values(['XP Granted', 'Min Level'], ascending=[False, False], inplace=True)\n",
    "\n",
    "    # 判断进入地下城次数\n",
    "    if visit_on_degree % 3 == 1:\n",
    "        data = df[df['Visit'] == '1, 4, 7,…']\n",
    "    elif visit_on_degree % 3 == 2:\n",
    "        data = df[df['Visit'] == '2, 5, 8,…']\n",
    "    else:\n",
    "        data = df[df['Visit'] == '3, 6, 9,…'] \n",
    "    \n",
    "    \n",
    "    if player_class != data['Class'].values[0]:\n",
    "        # Warlock单独判断\n",
    "        if player_class == 'Warlock':\n",
    "            if data['Class'].values[0] == 'Warlock, Mage':\n",
    "                if armor_stats <= data['Stats Amount'].values[0]: # 丢弃旧装备\n",
    "                    gold_granted = gold_granted + data['Gold Granted'].values[0] + data['Sales Price'].values[0]\n",
    "                    # armor_price = data['Sales Price'].values[0]\n",
    "                    stats_amount = stats_amount + data['Stats Amount'].values[0] - armor_stats\n",
    "                    armor_stats = data['Stats Amount'].values[0]\n",
    "                    armor = data['Gear Reward (Weapons)'].values[0]\n",
    "                else: # 丢弃新装备\n",
    "                    gold_granted += data['Gold Granted'].values[0]\n",
    "            else:\n",
    "                gold_granted = gold_granted + data['Gold Granted'].values[0] + data['Sales Price'].values[0]\n",
    "        else:\n",
    "            gold_granted = gold_granted + data['Gold Granted'].values[0] + data['Sales Price'].values[0]\n",
    "    else:\n",
    "        # 判断新获得的装备是否比旧装备强，强则丢弃旧装备，反之丢弃新装备\n",
    "        if armor_stats <= data['Stats Amount'].values[0]: # 丢弃旧装备\n",
    "            gold_granted = gold_granted + data['Gold Granted'].values[0] + data['Sales Price'].values[0]\n",
    "            # armor_price = data['Sales Price'].values[0]\n",
    "            stats_amount = stats_amount + data['Stats Amount'].values[0] - armor_stats\n",
    "            armor_stats = data['Stats Amount'].values[0]\n",
    "            armor = data['Gear Reward (Weapons)'].values[0]\n",
    "        else: # 丢弃新装备\n",
    "            gold_granted = gold_granted + data['Gold Granted'].values[0] + data['Sales Price'].values[0]\n",
    "            \n",
    "\n",
    "    # 判断等级\n",
    "    player_xp += data['XP Granted'].values[0]\n",
    "    player_degree = [player_xp >= i for i in total_xp].index(False)\n",
    "    print(player_xp, player_degree, gold_granted, stats_amount, armor_stats)\n",
    "    if player_degree == 60:\n",
    "        break\n",
    "    else:\n",
    "        # 查看是否能否开启下一级地下城\n",
    "        if df.shape[0] < dungeons[dungeons['Min Level'] <= player_degree].shape[0]: # 能够开启下一个地下城\n",
    "            visit_on_degree = 1 # 探索次数重置为1\n",
    "        else:\n",
    "            visit_on_degree += 1 \n",
    "            \n",
    "print(gold_granted*100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fbe0327d-b4ee-45a1-a2e2-113d9965abc2",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "36661dec-c24a-4446-a27c-851afa2cbcdb",
   "metadata": {},
   "outputs": [],
   "source": [
    "player_list = [\n",
    "    {\n",
    "        'player_id': 'David',\n",
    "        'race': 'Orc',\n",
    "        'class': 'Warlock',\n",
    "        'xp': 336368,\n",
    "    },\n",
    "    {\n",
    "        'player_id': 1,\n",
    "        'race': 'Orc',\n",
    "        'class': 'Warrior',\n",
    "        'xp': 329970,\n",
    "    },\n",
    "    {\n",
    "        'player_id': 2,\n",
    "        'race': 'Troll',\n",
    "        'class': 'Priest',\n",
    "        'xp': 330822,\n",
    "    },\n",
    "    {\n",
    "        'player_id': 3,\n",
    "        'race': 'Undead',\n",
    "        'class': 'Warlock',\n",
    "        'xp': 337660,\n",
    "    },\n",
    "    {\n",
    "        'player_id': 4,\n",
    "        'race': 'Tauren',\n",
    "        'class': 'Warrior',\n",
    "        'xp': 328716,\n",
    "    },\n",
    "        {\n",
    "        'player_id': 5,\n",
    "        'race': 'Tauren',\n",
    "        'class': 'Hunter',\n",
    "        'xp': 329802,\n",
    "    },\n",
    "    {\n",
    "        'player_id': 6,\n",
    "        'race': 'Undead',\n",
    "        'class': 'Priest',\n",
    "        'xp': 328639,\n",
    "    },\n",
    "    {\n",
    "        'player_id': 7,\n",
    "        'race': 'Troll',\n",
    "        'class': 'Hunter',\n",
    "        'xp': 331890,\n",
    "    },\n",
    "    {\n",
    "        'player_id': 8,\n",
    "        'race': 'Orc',\n",
    "        'class': 'Rogue',\n",
    "        'xp': 333728,\n",
    "    },\n",
    "        {\n",
    "        'player_id': 9,\n",
    "        'race': 'Orc',\n",
    "        'class': 'Shaman',\n",
    "        'xp': 338658,\n",
    "    },\n",
    "    {\n",
    "        'player_id': 10,\n",
    "        'race': 'Undead',\n",
    "        'class': 'Mage',\n",
    "        'xp': 352717,\n",
    "    },\n",
    "    {\n",
    "        'player_id': 11,\n",
    "        'race': 'Orc',\n",
    "        'class': 'Warlock',\n",
    "        'xp': 335672,\n",
    "    },\n",
    "    {\n",
    "        'player_id': 12,\n",
    "        'race': 'Troll',\n",
    "        'class': 'Warrior',\n",
    "        'xp': 330517,\n",
    "    },\n",
    "    {\n",
    "        'player_id': 13,\n",
    "        'race': 'Undead',\n",
    "        'class': 'Rogue',\n",
    "        'xp': 329802,\n",
    "    },\n",
    "    {\n",
    "        'player_id': 14,\n",
    "        'race': 'Troll',\n",
    "        'class': 'Mage',\n",
    "        'xp': 349550,\n",
    "    },\n",
    "    {\n",
    "        'player_id': 15,\n",
    "        'race': 'Tauren',\n",
    "        'class': 'Shaman',\n",
    "        'xp': 338297,\n",
    "    },\n",
    "    {\n",
    "        'player_id': 16,\n",
    "        'race': 'Troll',\n",
    "        'class': 'Shaman',\n",
    "        'xp': 337089,\n",
    "    },\n",
    "            {\n",
    "        'player_id': 17,\n",
    "        'race': 'Undead',\n",
    "        'class': 'Rogue',\n",
    "        'xp': 333255,\n",
    "    },\n",
    "    {\n",
    "        'player_id': 18,\n",
    "        'race': 'Troll',\n",
    "        'class': 'Priest',\n",
    "        'xp': 334176,\n",
    "    },\n",
    "    {\n",
    "        'player_id': 19,\n",
    "        'race': 'Troll',\n",
    "        'class': 'Priest',\n",
    "        'xp': 328850,\n",
    "    },\n",
    "    {\n",
    "        'player_id': 20,\n",
    "        'race': 'Tauren',\n",
    "        'class': 'Druid',\n",
    "        'xp': 348194,\n",
    "    }\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c5982294-fa35-46e1-91d4-71638bc12832",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "595ea39f-aad9-4745-9171-a4cc878ba8d4",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "88f6afcc-268d-47d6-9818-fb7e5eccc851",
   "metadata": {},
   "outputs": [],
   "source": [
    "# L6\n",
    "property = pd.read_excel('L6.xlsx')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "anaconda-2024.02-py310",
   "language": "python",
   "name": "conda-env-anaconda-2024.02-py310-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
